home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / FocusEvent.java < prev    next >
Text File  |  1998-09-22  |  4KB  |  115 lines

  1. /*
  2.  * @(#)FocusEvent.java    1.15 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.event;
  16.  
  17. import java.awt.Component;
  18. import java.awt.Event;
  19.  
  20. /**
  21.  * The component-level focus event.
  22.  * There are two levels of focus change events: permanent and temporary.
  23.  * Permanent focus change events occur when focus is directly moved
  24.  * from one component to another, such as through calls to requestFocus()
  25.  * or as the user uses the Tab key to traverse components.
  26.  * Temporary focus change events occur when focus is temporarily
  27.  * gained or lost for a component as the indirect result of another
  28.  * operation, such as window deactivation or a scrollbar drag.  In this
  29.  * case, the original focus state will automatically be restored once
  30.  * that operation is finished, or, for the case of window deactivation,
  31.  * when the window is reactivated.  Both permanent and temporary focus
  32.  * events are delivered using the FOCUS_GAINED and FOCUS_LOST event ids;
  33.  * the levels may be distinguished in the event using the isTemporary()
  34.  * method.
  35.  *  
  36.  * @version 1.15 07/01/98
  37.  * @author Carl Quinn
  38.  * @author Amy Fowler
  39.  */
  40. public class FocusEvent extends ComponentEvent {
  41.  
  42.     /**
  43.      * Marks the first integer id for the range of focus event ids.
  44.      */    
  45.     public static final int FOCUS_FIRST        = 1004;
  46.  
  47.     /**
  48.      * Marks the last integer id for the range of focus event ids.
  49.      */
  50.     public static final int FOCUS_LAST        = 1005;
  51.  
  52.     /**
  53.      * The focus gained event type.  
  54.      */
  55.     public static final int FOCUS_GAINED = FOCUS_FIRST; //Event.GOT_FOCUS
  56.  
  57.     /**
  58.      * The focus lost event type.  
  59.      */
  60.     public static final int FOCUS_LOST = 1 + FOCUS_FIRST; //Event.LOST_FOCUS
  61.  
  62.     boolean temporary = false;
  63.  
  64.     /*
  65.      * JDK 1.1 serialVersionUID 
  66.      */
  67.      private static final long serialVersionUID = 523753786457416396L;
  68.  
  69.     /**
  70.      * Constructs a FocusEvent object with the specified source component,
  71.      * type, and whether or not the focus event is a temporary level event.
  72.      * @param source the object where the event originated
  73.      * @id the event type
  74.      * @temporary whether or not this focus change is temporary
  75.      */
  76.     public FocusEvent(Component source, int id, boolean temporary) {
  77.         super(source, id);
  78.         this.temporary = temporary;
  79.     }
  80.  
  81.     /**
  82.      * Constructs a permanent-level FocusEvent object with the 
  83.      * specified source component and type.
  84.      * @param source the object where the event originated
  85.      * @id the event type
  86.      */
  87.     public FocusEvent(Component source, int id) {
  88.         this(source, id, false);
  89.     }
  90.  
  91.     /**
  92.      * Returns whether or not this focus change event is a temporary
  93.      * change.
  94.      */
  95.     public boolean isTemporary() {
  96.         return temporary;
  97.     }
  98.  
  99.     public String paramString() {
  100.         String typeStr;
  101.         switch(id) {
  102.           case FOCUS_GAINED:
  103.               typeStr = "FOCUS_GAINED";
  104.               break;
  105.           case FOCUS_LOST:
  106.               typeStr = "FOCUS_LOST";
  107.               break;
  108.           default:
  109.               typeStr = "unknown type";
  110.         }
  111.         return typeStr + (temporary? ",temporary" : ",permanent");
  112.     }
  113.  
  114. }
  115.